<div id="login_popup" title="Autenticarme">
	<table class="form-table">		
		<tr>
			<td><label for="login_email">E-mail:</label></td>
			<td>
				<input id="login_email" maxlength="45" name="login_email" class="validate[required, custom[email]]"/>		
			</td>
		</tr>
		
		<tr>
			<td><label for="login_email">Password:</label></td>
			<td>
				<input id="login_password" maxlength="45" type="password" name="login_password" class="validate[required, minSize[6]]"/>		
			</td>
		</tr>
		
		<tr>
			<td colspan="2" style="text-align: center;">
				<a href="#" id="login_button" >Login</a>
			</td>
		</tr>		
	</table>
</div>

<script type="text/javascript">

	// Init
	$(function() {
		var login_popup = $("#login_popup");
		
		login_popup.dialog({
			autoOpen: false,
			height: 170,
			position: {
				my: "right top",
				at: "right-4 top",
				of: "#menu"
			}
		});

		$("#login_button").click(function(){
			
			var email = $("#login_email");
			var password = $("#login_password");

			if(email.val() == "")
			{				
				email.css("border", "1px solid #FF0000");
				$('label[for="' + email.attr('id') + '"]').css("color", "#FF0000");				
			} 

			if(password.val() == "")
			{
				password.css("border", "1px solid #FF0000");
				$('label[for="' + password.attr('id') + '"]').css("color", "#FF0000")
			} 
			
			if(email.val() != "" && password.val() != "")
			{
				var xhr = $.post("<?php echo site_url(array("inicio", "autenticar"));?>", {login_email: email.val(), login_password: password.val()});

				xhr.done(function(){
					window.location.href = "<?php echo site_url(array("inicio"));?>";				
				});

				xhr.fail(function(e){
					alert(e);
				});
			}
		});
	});
	
	function login_popup_open(caller)
	{
		$("#login_popup").dialog("open");
	}
	
</script>
